/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.sys.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.thinkgem.jeesite.common.utils.TimeUtil;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.pro.entity.ProjectTask;
import com.thinkgem.jeesite.modules.pro.service.ProjectTaskService;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;

/**
 * 工作面板controller
 * @author fanqinglong
 *
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/panel")
public class PanelController extends BaseController{
	@Autowired
	private ProjectTaskService projectTaskService;
	
	/**
	 * 跳转到工作面板，并初始化数据
	 * @return
	 */
	@RequestMapping(value = {"workPanel", ""})
	public String workPanel(HttpServletRequest request, HttpServletResponse response, Model model){
		// 获取当前登录用户
		User user = UserUtils.getUser();
		ProjectTask param = new ProjectTask();
		param.setManager(user);
		//取的是所有任务
		List<ProjectTask> list = projectTaskService.findListForPanel(param);
		List<ProjectTask> ongoingList = new ArrayList<>();
		List<ProjectTask> pendingList = new ArrayList<>();
		List<ProjectTask> deleteList = new ArrayList<>();
		for (int i = 0; i < list.size(); i++) {
			ProjectTask projectTask = list.get(i);
			if ("0".equals(projectTask.getDelFlag())) {
				if (projectTask.getStartTime().before(TimeUtil.getNowDate())) {
					ongoingList.add(projectTask);
				}else {
					pendingList.add(projectTask);
				}
			}else {
				deleteList.add(projectTask);
			}
		}
		model.addAttribute("taskList", pendingList);
		model.addAttribute("ongoingList", ongoingList);
		model.addAttribute("deleteList", deleteList);
		return "modules/sys/workPanel";
	}
}
